package org.rocky.provider.controller;

import org.rocky.provider.exception.HostException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Rocky
 * @date 2020/2/16 21:59
 */


@RequestMapping("/provider")
@RestController
public class MsgSenderController {

    Logger log =  LoggerFactory.getLogger(MsgSenderController.class);
    private RabbitTemplate rabbitTemplate;


    @Autowired
    public MsgSenderController( RabbitTemplate rabbitTemplate){
        this.rabbitTemplate= rabbitTemplate;
    }

    /**
     * 发送消息到4个队列
     * 已经配置了异步消息确认机制的话不影响服务
      * @return 必定返回成功
     */
    @RequestMapping("/sendRabbitMsg")
    public String rabbitSend(){
        // 发送4条消息
        rabbitTemplate.convertAndSend("DIRECT_EXCHANGE","rocky.exchange","rabbit-------- a direct msg");
        rabbitTemplate.convertAndSend("TOPIC_EXCHANGE","rocky.today","rabbit-------- a prefix match topic msg ");
        rabbitTemplate.convertAndSend("TOPIC_EXCHANGE","today.exchange","rabbit-------- a suffix match topic msg ");
        rabbitTemplate.convertAndSend("FANOUT_EXCHANGE","","rabbit-------- a fanout msg");
        return "success";
    }








}
